package com.burpee.service;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.burpee.dao.AuthorityDao;
import com.burpee.dao.HealthpointDao;
import com.burpee.dao.MemberDao;
import com.burpee.ui.Authority;
import com.burpee.ui.Healthpoint;
import com.burpee.ui.Member;

@Service(value="memberService")
@Transactional
public class MemberServiceImpl implements MemberService {

	@Autowired
	MemberDao memberDao;
	@Autowired
	AuthorityDao authorityDao;
	@Autowired
	HealthpointDao healthpointDao;
	
	public boolean login(Member member) {
		return memberDao.login(member);
		
	}
	
	

	public List<Member> list() {
		return memberDao.list();
	}



	public Member view(String memberId) {
		return memberDao.view(memberId);
	}
	
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean memberadd(Member member) {
		int result = 0;
		
		Authority authority = new Authority();
		Healthpoint healthpoint = new Healthpoint();
		
		authority.setAuthorityBoardInsert("N");
		authority.setAuthorityBoardItemsModify("N");
		authority.setAuthorityBoardItemsNotice("N");
		authority.setAuthorityBoardItemsRemove("N");
		authority.setAuthorityBoardModify("N");
		authority.setAuthorityBoardRemove("N");
		authority.setAuthorityCoordinateInsert("N");
		authority.setAuthorityCoordinateModify("N");
		authority.setAuthorityCoordinateRemove("N");
		authority.setAuthorityExercisefoodInsert("N");
		authority.setAuthorityExercisefoodModify("N");
		authority.setAuthorityExercisefoodRemove("N");
		authority.setAuthorityFilesRemove("N");
		authority.setAuthorityGroupRemove("N");
		authority.setAuthorityMemberview("N");
		authority.setAuthorityScheduleInsert("N");
		authority.setAuthorityScheduleModify("N");
		authority.setAuthorityScheduleRemove("N");
		authority.setMemberId(member.getMemberId());
		
		healthpoint.setHealthpointChange(100);
		healthpoint.setHealthpointInfomation("회원가입 포인트");
		healthpoint.setHealthpointTotal(100);
		healthpoint.setInputDate(new Date(System.currentTimeMillis()));
		healthpoint.setMemberId(member.getMemberId());
		
		if(memberDao.memberadd(member) > 0 && authorityDao.add(authority) >0  && healthpointDao.add(healthpoint)>0)
		{
			return true;
		} else {
			return false;
		}		
	}



	public boolean membermodify(Member member) {
		if(memberDao.membermodify(member) > 0){
			return true;
		}
		else{
			
			return false;
		}
	}



	public boolean memberRemove(String[] checkboxmemberId) {
		
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.memberRemove(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}

	public boolean memberRemoveCancel(String[] checkboxmemberId) {
		
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.memberRemoveCancel(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}



	public boolean adminAdminLevel(String[] checkboxmemberId) {
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.adminAdminLevel(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}



	public boolean adminTrainerLevel(String[] checkboxmemberId) {
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.adminTrainerLevel(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}



	public boolean adminGeneralMemberLevel(String[] checkboxmemberId) {
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.adminGeneralMemberLevel(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}



	public boolean adminFreshMemberLevel(String[] checkboxmemberId) {
		int result = 0;
		
		int checkboxtotal = checkboxmemberId.length;
		
		for(int i = 0; i < checkboxtotal; i++){
			result = memberDao.adminFreshMemberLevel(checkboxmemberId[i]);
		}

		if(result > 0){
			return true;
		}
		else{
			return false;
		}
	}



	public int adminMemberCount() {
		return memberDao.adminMemberCount();
	}



	public List<Member> adminMemberList(int currentPage) {
		return memberDao.adminMemberList(currentPage);
	}

	


	
	

}
